<template>
  <div class="app-container">

    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-form :inline="true">

        <!--<el-button class="filter-item" type="primary" icon="el-icon-plus" @click="startAdd">添加</el-button>-->
        <el-button class="filter-item" style="float:right" type="primary" icon="el-icon-search" @click="handleFilter">查询</el-button>
        <el-form-item label="角色名称" style="float:right">
          <el-input v-model="listQuery.roleName" clearable class="filter-item" style="width: 120px;" placeholder=""/>
        </el-form-item>
        <el-form-item label="操作人" style="float:right">
          <el-input v-model="listQuery.userName" clearable class="filter-item" style="width: 120px;" placeholder=""/>
        </el-form-item>
        <el-form-item label="时间" style="float:right">
          <el-col :span="11">
            <el-date-picker v-model="listQuery.startTime" type="datetime" placeholder="开始时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"/>
          </el-col>
          <el-col :span="2" class="line" align="center">至</el-col>
          <el-col :span="11">
            <el-date-picker v-model="listQuery.endTime" type="datetime" placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"/>
          </el-col>
        </el-form-item>
      </el-form>
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row>

      <el-table-column align="center" label="操作人" prop="userName"/>

      <el-table-column align="center" label="角色名称" prop="roleName"/>

      <el-table-column align="center" label="操作时间" prop="createTime"/>

      <el-table-column align="center" label="操作IP" prop="ip"/>

      <el-table-column align="center" label="操作页面" prop="module"/>
      <el-table-column align="center" label="操作类型" prop="type"/>
      <el-table-column align="center" label="说明" prop="description"/>

      <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="deleteSysOperateItem(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />

  </div>
</template>

<script>
import { listSysOperate, deleteSysOperate } from '@/api/sysOperate'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'SysOperate',
  components: { Pagination },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        pageSize: 20,
        userName: undefined,
        roleName: undefined
      },
      downloadLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      listSysOperate(this.listQuery).then(response => {
        this.list = response.data.data.list
        this.total = response.data.data.total
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    deleteSysOperateItem(itemId) {
      const resetData = { 'id': itemId }
      deleteSysOperate(resetData).then(response => {
        this.getList()
      })
    }
  }
}
</script>
